<?php
//以下2行随客户公众号不同需更改
$shareUrl='qinyuan';
$appIdKey='qinyuan_appid';
try {
        if(stripos($_SERVER["PHP_SELF"], '/index.php')===0){
            $_SERVER["PHP_SELF"]=str_ireplace('/index.php', '', $_SERVER["PHP_SELF"]);
        }
        $cur_url=$_SERVER["HTTP_HOST"]."/Home/Getxinxi/".$shareUrl;
        if($_SERVER["QUERY_STRING"]){
            $cur_url=$cur_url."?".$_SERVER["QUERY_STRING"];
        }
        $cur_url='http://' .$cur_url;
        // $cur_url=htmlspecialchars($cur_url);
    	$appId = C($appIdKey);
        $thirdAppid=C('third_app_id');
        $thirdAppsecret=C('third_app_secret');
        $m=D('Home/AuthorizationInfo');
        $api_authorizer_token=$m->getAuthorizerAccessToken($appId);
    	$sdk = new \Home\ORG\WeixinThirdSDK($thirdAppid,$thirdAppsecret);
    	$jsapi_ticket = $sdk->getThirdJs_ticket($api_authorizer_token);
    	$timestamp = time();
    	$nonceStr =$sdk->createNonceStr();
    	$str = "jsapi_ticket=" . $jsapi_ticket . "&noncestr=" . $nonceStr . "&timestamp=" . $timestamp . "&url=" . $cur_url;
        $signature = sha1($str);
    	$signPackage = array();
    	$signPackage['appId'] = $appId;
        $signPackage['timestamp'] = $timestamp;
        $signPackage['nonceStr'] = $nonceStr;
        $signPackage['signature'] = $signature;
        //以下信息不必要，仅供调试用
        $signPackage['cur_url'] = $cur_url;
        $signPackage['ticket'] = $jsapi_ticket;
        $signPackage['str'] = $str;
    } catch (Exception $e) {
    	// console.log('获得自定义分享参数失败:'.$e->getMessage());
        print $e->getMessage();
    }
?>
<html>
<head>
	<title>沁园公众号网页授权测试</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"/>
	<link rel="stylesheet" href="http://demo.open.weixin.qq.com/jssdk/css/style.css?ts=1420774989">
</head>
<body>
	<h5>请点击右上角选择分享给朋友或朋友圈</h5>
	
</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"> </script>
<script>
    var wx_link='<?php echo $cur_url ?>'; 
    var wx_imgUrl = 'http://' + '<?php echo$_SERVER['HTTP_HOST']?>' + '/Public/img/wx_share_icon.png';
  wx.config({
      debug: false,
      appId: '<?php echo $signPackage["appId"];?>',
      timestamp: '<?php echo $signPackage["timestamp"];?>',
      nonceStr: '<?php echo $signPackage["nonceStr"];?>',
      signature: '<?php echo $signPackage["signature"];?>',
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
      ]
  });
    wx.error(function(res) {
            //alert(res);
            
        });
        
        var wx_init=function(){
            wx.onMenuShareAppMessage({
                title: '分享标题qy',
                desc: '分享正文qy', 
                link: wx_link, 
                imgUrl: wx_imgUrl, 
                type: '', 
                dataUrl: '', 
                success: function() {
                    
                },
                cancel: function() {
                   
                }
            });
            wx.onMenuShareTimeline({
                title: '分享朋友圈标题qy',
                link: wx_link,
                imgUrl: wx_imgUrl,
                success: function() {
                   
                },
                cancel: function() {
                }
            });

    }

    wx.ready(wx_init);
</script>

<script type="text/javascript">
	// wx.checkJsApi({
	//     jsApiList: ['chooseImage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
	//     success: function(res) {
	//         // 以键值对的形式返回，可用的api值true，不可用为false
	//         // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
	//     }
	// });
	// wx.ready(function () {
   //      var latitude,longitude,speed,accuracy;
	  //   document.querySelector('#lo').onclick = function () {
   //  	    wx.getLocation({
   //              type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
   //              success: function (res) {
   //                   latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
   //                   longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
   //                   speed = res.speed; // 速度，以米/每秒计
   //                   accuracy = res.accuracy; // 位置精度
   //                   alert('获得位置成功');
   //              },
   //              cancel: function (res) {
                     
   //                   alert(' 你取消了位置获取，无法为你导航');
   //              }
   //          });
	  // };
   //    document.querySelector('#showlo').onclick = function () {
   //          wx.openLocation({
   //          latitude: 31.230416, // 纬度，浮点数，范围为90 ~ -90
   //          longitude: 121.473701, // 经度，浮点数，范围为180 ~ -180。
   //          name: '江南名庐', // 位置名
   //          address: '白玉路98弄', // 地址详情说明
   //          scale: 14, // 地图缩放级别,整形值,范围从1~28。默认为最大
   //          infoUrl: 'http://www.eosi.com.cn' // 在查看位置界面底部显示的超链接,可点击跳转
   //      });
   //    };
 //  });
  
</script>
</html>